<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise-封装</title>
    <script src="./promise.js"></script>
</head>
<body>
    <script>
        /* let p = new Promise((resolve,reject)=>{
            setTimeout(() => {
                resolve("OK");
                // reject("error");
                // 抛出异常
                // throw "failure";
            }, 1000);
        }) */

        /* let res = p.then(value=>{
            console.log(value);
            // return "hello promise";
            // return new Promise((resolve,reject)=>{
            //     // resolve("success");
            //     reject("no");
            // })
            // throw "failure";
        },reason=>{
            console.warn(reason);
            // throw "failure";
        }) */

        /* let res = p.catch(reason=>{
            console.warn(reason);
        }) */

        /* let res = p.then().then(value=>{
            console.log(222);
        }).then(value=>{
            console.log(333);
        }).catch(reason=>{
            console.warn(reason);
        }) */

        // const p = Promise.resolve("OK");
        // const p2 = Promise.resolve(new Promise((resolve,reject)=>{
        //     reject("error");
        // }));

        // console.log(p);
        // console.log(p2);
        // console.log(res);

        /* const p = Promise.reject("ERROR");
        const p2 = Promise.reject(new Promise((resolve,reject)=>{
            resolve("OK");
        }));
        console.log(p);
        console.log(p2); */

        /* let p1 = new Promise((resolve,reject)=>{
            setTimeout(() => {
                resolve("OK");
            }, 1000);
        });
        let p2 = Promise.resolve("success");
        let p3 = Promise.resolve("oh yeah");

        let result = Promise.race([p1,p2,p3]);
        console.log(result); */

        let p1 = new Promise((resolve,reject)=>{
            resolve("ok");
            console.log(111);
        })

        p1.then(value=>{
            console.log(222);
        })

        console.log(333);
    </script>
</body>
</html>